#include <soar.h>

int main(int argc, char *argv[])
{
    char algm_desc[10];
    unsigned int algm;
    int loop_num;
    char *data="1234567890123456789012345678901234567890\n";
    char value[100];
    int value_size;
    char plain[200];
    time_t begin, end;
    int i;
    int res;

    if(argc > 1)
    {
        if(strcasecmp(argv[1], "md5") == 0)
        {
            strcpy(algm_desc, argv[1]);
            algm=OSSL_DIGEST_MD5;
        }
        if(strcasecmp(argv[1], "sha1") == 0)
        {
            strcpy(algm_desc, argv[1]);
            algm=OSSL_DIGEST_SHA1;
        }
        else
        {
            strcpy(algm_desc, "md5");
            algm=OSSL_DIGEST_MD5;
        }
        if(argc > 2)
        {
            if((loop_num=atoi(argv[2])) == 0)
                loop_num=1000000;
        }
        else
            loop_num=1000000;
    }
    else
    {
        strcpy(algm_desc, "md5");
        algm=OSSL_DIGEST_MD5;
        loop_num=1000000;
    }

    begin=curr_timestamp(NULL);

    ossl_init();
    for(i=0; i<loop_num; ++i)
    {
        if((res=ossl_digest(algm,
                        (unsigned char *)data, strlen(data),
                        (unsigned char *)value, &value_size)))
        {
            printf("ossl_digest fail, res::%d\n", res);
            break;
        }
    }
    ossl_clean();

    end=curr_timestamp(NULL);

    printf("Digest: %s\n",
            expand_to_str((unsigned char *)value, value_size, plain));
    printf("Algorithm: %s       Loop: %d\n", algm_desc, loop_num);
    printf("Cost: %d\n", (int)(end-begin));

    return(0);
}
